<!-- 表格插件 -->
<script src="/static/plugins/bootstrap-table/bootstrap-table.js" type="text/javascript"></script>
<script src="/static/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js" type="text/javascript"></script>
<script src="/static/plugins/bootstrap-table/cookie/bootstrap-table-cookie.js"></script>

<!-- FLOT CHARTS -->
<script src="/static/plugins/flot/jquery.flot.min.js"></script>
<!-- FLOT RESIZE PLUGIN - allows the chart to redraw when the window is resized -->
<script src="/static/plugins/flot/jquery.flot.resize.min.js"></script>
<!-- FLOT PIE PLUGIN - also used to draw donut charts -->
<script src="/static/plugins/flot/jquery.flot.pie.min.js"></script>
<!-- FLOT CATEGORIES PLUGIN - Used to draw bar charts -->
<script src="/static/plugins/flot/jquery.flot.categories.min.js"></script>

<!-- x-editable插件 -->
<script src="/static/plugins/x-editable/js/bootstrap-editable.min.js"></script>
<!-- bootstrap-table启用x-editable插件 -->
<script src="/static/plugins/bootstrap-table/bootstrap-table-editable.js"></script>
<script src="/static/product/scripts/common.js"></script>

<script>
    //初始化加载
    $(function () {
        schoolSelectInit();
        total();
    });
    /*
     * BAR CHART
     * ---------
     */

    var bar_data = {
        data: [["January", 10], ["February", 8], ["March", 4], ["April", 13], ["May", 17], ["June", 9]],
        color: "#3c8dbc"
    };
    console.log(bar_data);
    // $.plot("#bar-chart", [bar_data], {
    //     grid: {
    //         borderWidth: 1,
    //         borderColor: "#f3f3f3",
    //         tickColor: "#f3f3f3"
    //     },
    //     series: {
    //         bars: {
    //             show: true,
    //             barWidth: 0.5,
    //             align: "center"
    //         }
    //     },
    //     xaxis: {
    //         mode: "categories",
    //         tickLength: 0
    //     }
    // });
    /* END BAR CHART */
    /*
     * DONUT CHART
     */
    function total() {
        var url = '{{ urlfor "student/ContractController.NewData"}}';
        var data = $("#searchForm").serialize();
        $.sdpost(url, data, function (re) {
            var bar_data = {data:re.obj, color:"#3c8dbc"};
            console.log(bar_data);
            $.plot("#bar-chart", [bar_data], {
                grid: {
                    borderWidth: 1,
                    borderColor: "#f3f3f3",
                    tickColor: "#f3f3f3"
                },
                series: {
                    bars: {
                        show: true,
                        barWidth: 0.5,
                        align: "center"
                    }
                },
                xaxis: {
                    mode: "categories",
                    tickLength: 0
                }
            });
        });

    }
    /*
     * END DONUT CHART
     */
    //清除搜索
    $("#btnClearSearch").on("click", function (e) {
        $searchForm = $("#searchForm");
        $('select', $searchForm).selectpicker('val', '');
        $('input', $searchForm).val('');
        refreshToFirstPage();
    });
    //刷新并跳转至第一页
    function refreshToFirstPage() {
        total();
    }
    // 校区下拉框初始化
    function schoolSelectInit() {
        var url = '{{urlfor "student/SchoolController.DataList"}}';
        var $select = $("#SchoolId");
        $select.html('');
        $.sdpost(url,{},function (re) {
            if(re.code === 0) {
                var html=[];
                $(re.obj).each(function(i,e){
                    html.push('<option value="' + e.id + '">' + e.name + '</option>')
                });
                $select.html(html.join(''));
                $select.selectpicker({liveSearch:true});
                $select.selectpicker('val',[0]);
            }else {
                layer.alert("获取数据失败",{icon:2,title:'失败'})
            }
        })
    }

</script>